package doublepoint;

/**
 * @Author: 海琳琦
 * @Date: 2022/2/3 21:18
 * https://leetcode-cn.com/problems/squares-of-a-sorted-array/
 */
public class SortedSquares {

    public int[] sortedSquares(int[] nums) {
        int firstIndex = 0, endIndex = nums.length - 1;
        int[] result = new int[nums.length];
        int resultIndex = endIndex;
        while (firstIndex <= endIndex) {
            if (-nums[firstIndex] > nums[endIndex]) {
                result[resultIndex--] = nums[firstIndex] * nums[firstIndex];
                firstIndex++;
            }else{
                result[resultIndex--] = nums[endIndex] * nums[endIndex];
                endIndex--;
            }
        }
        return result;
    }

    public static void main(String[] args) {

    }
}
